package com.stockz.watchlist.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@SequenceGenerator(initialValue=1,allocationSize=1,
name="WatchListIdSequenceGenerator",sequenceName="WATCHLIST_ID_SEQ")
public class WatchList implements Serializable {
	private static final long serialVersionUID = 2508138942867072680L;

	private Long id;
	private String name;
	private String description;
	private Date createDate;
	
	@Override
	public String toString() {
		return id+" : "+name+" : "+description+" : "+createDate;
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="WatchListIdSequenceGenerator")
	@Column
	public Long getId(){
		return this.id;
	}
	public void setId(Long id){
		this.id = id;
	}
	
	@Column(nullable=false,unique=true)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column
	@Lob
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@Column(insertable=true,updatable=false)
	@Temporal(TemporalType.DATE)
	public Date getCreateDate() {
		return createDate;
	}
	
	@PrePersist
	private void prePersist(){
		this.createDate = new Date();
	}
	
	private void setCreateDate(Date createDate) {
		this.createDate = new Date();
	}
}
